layui.use(['table', 'admin', 'ax'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;

    /**
     * 管理
     */
    var Product = {
        tableId: "productListTable"
    };

    /**
     * 初始化表格的列
     */
    Product.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键'},
            {field: 'productName', hide: false, title: '产品'},
            {field: 'productModelName', sort: true, title: '产品型号'},
            {field: 'productOrderName', sort: true, title: '产品编号'},
            {field: 'productOrderId', sort: true,hide:true},
            {field: 'colorNumber', sort: true, title: '产品色号'},
            {field: 'amount', sort: true, title: '数量'},
            {field: 'batchNumber', sort: true, title: '批次'},
            {field: 'warhouseStr', sort: true, title: '仓库'},
            {field: 'serialNum', sort: true,hide:true, title: '序列号'}
        ]];
    };

    /**
     * 点击查询按钮
     */
    Product.search = function () {
        var queryData = {};
        queryData['condition'] = $("#condition").val();
        table.reload(Product.tableId, {where: queryData});
    };


    // var $ = layui.$, active = {
    //     getCheckData: function(){ //获取选中数据
    //         var checkStatus = table.checkStatus('productTable')
    //             ,data = checkStatus.data;
    //         layer.alert(JSON.stringify(data));
    //     }
    // };

    $("#getProductList").click(function () {
        var checkStatus = table.checkStatus('productListTable'),
            data = checkStatus.data;
        for (var i = 0; i < data.length; i++) {
            data[i].orderId = null;
            data[i].unitsName = "请填写单位";
            data[i].unitsRate = "";
            data[i].unitsId = "";
            data[i].productTaxFreeUnitPrice = "请填写单价";
            data[i].remark = "";
            data[i].orderIsGifts = "";
            data[i].orderAmount = "";
            data[i].productTaxIncludedUnitPrice = 0;
            data[i].orderNumbers = 0;
            data[i].batchNumber = "请填写批次";
            data[i].warhouseId = "请选择仓库";
            data[i].serialNum = "请填写序列号";
            data[i].warhouseName ="";
        }
        admin.putTempData("product_list", data);
        admin.closeThisDialog();
        // layer.alert(JSON.stringify(data));
    });


    console.log( "传来的id是："+$("#dept").val());
    // 渲染表格
    var tableResult = table.render({
        elem: '#' + Product.tableId,
        url: Feng.ctxPath + '/inventoryOrder/getInventoryListByWarhouse/' + $("#dept").val(),
        page: true,
        height: "full-158",
        cellMinWidth: 100,
        cols: Product.initColumn()
    });


    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        Product.search();
    });




});
